#ifndef _FILEGETCONTENTS_HPP
#define _FILEGETCONTENTS_HPP

#include <fstream>

namespace builtin {
	class FunctionFileGetContents {
	public:
		Object* operator()(std::vector<Object*> argLists) {
			if (argLists.size() != 1) {
				return new Error("function file_get_contents must have 1 parameter");
			}
			if (argLists[0]->Type() != STRING_OBJECT) {
				return new Error("function file_get_contents's first parameter must be string");
			}
			std::fstream fstream;
			fstream.open(argLists[0]->examine(), ios_base::in);
			if (!fstream.is_open()) {
				return new Error("open file: " + argLists[0]->examine() + " filed");
			}
			std::string line;
			std::string contents;
			while (std::getline(fstream, line)) {
				contents.append(line);
			}
			return new StringObject(contents);
			return nullptr;
		}
	};
}

#endif // !_FILEGETCONTENTS_HPP
